package com.lanou3g.code0426;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * If there are no bugs, it was created by Chen FengYao on 2018/4/26;
 * Otherwise, I don't know who created it either
 */

public class Test02 {
    public static void main(String[] args) {
        try {
            // 整个项目中  驱动只需要注册一次
            Class.forName("com.mysql.cj.jdbc.Driver");

            // 每一次 执行sql 都 固定写的代码
            Connection conn = DriverManager
                    .getConnection(
                            "jdbc:mysql://localhost:3306/lan_ou?serverTimezone=UTC",
                            "root",
                            "123456");

            Statement statement = conn.createStatement();

            String sql = "insert into stu (sid, sname, age, gender) " +
                    "VALUES ('123456','张三',18,'男')";
            int rows = statement.executeUpdate(sql);
            if (rows > 0){
                System.out.println("插入成功");
            } else {
                System.out.println("插入失败");
            }

            statement.close();
            conn.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
